﻿package {
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	
	import com.googlecode.milib.MILibMain;
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.display.service.MLButton;
	import com.googlecode.milib.display.service.MLMC;
	import com.googlecode.milib.vo.MLEvent;
	import com.googlecode.milib.vo.MLEventInfo;
	import com.googlecode.milib.display.button.AbstractButton;	

	/**
	 * @author Marek Brun 'minim'
	 */
	public class ExampleMLButtonMain extends MovieClip implements IMLBroadcasterListener {
		
		private var mlmc:MLMC;
		private var mlButtonSome : MLButton;

		public function ExampleMLButtonMain() {
			stage.scaleMode=StageScaleMode.NO_SCALE; 
			stage.align=StageAlign.TOP_LEFT;
			MILibMain.init(this);
			
			var btnSome:MovieClip=MovieClip(getChildByName('btnSome'));
			
			//crating MLButton from factory method
			mlButtonSome=MLButton.forInstance(btnSome);
			
			
			//MLMC class can make life little easer
			mlmc=MLMC.forInstance(this);
			
			//other way to setup auto view
			//from MLMC you can get also child.child.[...] instances with comma separation
			mlButtonSome=mlmc.getMLButton('btnSome');
			
			mlmc.getMLButton('btnSome')==MLButton.forInstance(btnSome); //true
			
			//suscribing event listener
			mlButtonSome.addEventListener(mlButtonSome.event_Press, onBtnSomePress);
			
			//suscribing as a listener
			mlButtonSome.addListener(this);
			
			
		}
		
//********************************************************************************************
//		events for ExampleMLButtonMain
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case mlButtonSome:
					trace('mlButtonSome.event_'+ev.event);
					switch(ev.event) {
						case mlButtonSome.event_Over:
							
						break;
						case mlButtonSome.event_RollOver:
							
						break;
						case mlButtonSome.event_Release:
							
						break;
					}
				break;
			}
		}
		
		private function onBtnSomePress(event:MLEvent):void {
			trace('onBtnSomePress');
		}
		
	}
}
